package com.definity.toolkit.ui.widget;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.JButton;

import com.definity.toolkit.ui.Body;
import com.definity.toolkit.ui.action.ActionExecutor;

public class Button extends JButton implements WidgetExecutor<Button> {

	private static final long serialVersionUID = 9142046765627039087L;

	public Button() {
		super();
	}

	public Button(Icon icon) {
		super(icon);
	}

	public Button(String text, Icon icon) {
		super(text, icon);
	}

	public Button(String text) {
		super(text);
	}

	@Override
	public String id() {
		return getName();
	}

	@Override
	public Button id(String id) {
		setName(id);
		return this;
	}

	@Override
	public Button properties(Body<Button> body) {
		body.content(this);
		return this;
	}
	
	@Override
	public Button size(int width, int height) {
		setPreferredSize(new Dimension(width, height));
		return this;
	}
	
	public Button text(String text) {
		setText(text);
		return this;
	}

	@Override
	public Button action(final ActionExecutor executor) {
		addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				executor.execute(Button.this);
			}
		});
		return this;
	}

	@Override
	public Color background() {
		return getBackground();
	}

	@Override
	public Button background(Color background) {
		setBackground(background);
		return this;
	}

	@Override
	public Color foreground() {
		return getForeground();
	}

	@Override
	public Button foreground(Color foreground) {
		setForeground(foreground);
		return this;
	}

	@Override
	public Font font() {
		return getFont();
	}

	@Override
	public Button font(Font font) {
		setFont(font);
		return this;
	}
	
}
